package com.es.controller;

import com.es.entity.Hotel;
import com.es.service.EsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.elasticsearch.client.elc.ElasticsearchTemplate;
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
import org.springframework.data.elasticsearch.core.mapping.IndexCoordinates;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@SuppressWarnings("all")
@RestController
@RequestMapping("es")
public class TestController {

    @Autowired
    private EsService esService;

    @Autowired
    private ElasticsearchRestTemplate elasticsearchTemplate;

    @PostMapping("test")
    public List<Hotel> getRec() throws Exception{
        List<Hotel> hotelList = esService.getHotelFromTitle("再来");
        return hotelList;
    }

    @PostMapping("test1")
    public void save1(){
        Hotel hotel = new Hotel();
        hotel.setCity("测试酒店");
        hotel.setCity("西安");
        hotel.setPrice(456.23);
        Hotel hotel_document = elasticsearchTemplate.save(hotel, IndexCoordinates.of("hotel_document"));
        System.out.println(hotel_document);
    }
}
